package CarPackage;

import GoodsPackage.Good;
import GoodsPackage.GoodsDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/querycar.do")
public class QueryCarServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            HttpSession session = request.getSession();
            String id = request.getParameter("id");
            String user_id = (String) session.getAttribute("user_id");

            CarDao carDao = new CarDao();

            List<Car> carList = carDao.getCarByUserId(user_id);
            request.getSession().setAttribute("carList", carList);

            RequestDispatcher dispatcher = request.getRequestDispatcher("car.jsp");
            dispatcher.forward(request, response);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
